package com.beta.mq.redis.user.impl;

import com.beta.mq.redis.user.CurrentUserInvoker;
import com.beta.platform.rest.auth.LoginAccountDetail;
import com.beta.platform.rest.auth.LoginAccountSecurity;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author yliu2
 * @Date 2023/8/14 15:16
 * @Description 默认实现：网关通用获取当前用户
 */

@Slf4j
public class DefaultCurrentUserInvoker implements CurrentUserInvoker {

    @Override
    public String getCurrentUserId(HttpServletRequest request, HttpServletResponse response) {
        try{
            LoginAccountDetail accountDetail = LoginAccountSecurity.getLoginAccountDetail();
            return accountDetail.getThirdUserInfo().getUserId();
        }catch (Throwable e){
            log.warn("获取当前用户失败:{}",e.getMessage(),e);
            return "user";
        }
    }
}
